package org.apache.james.mime4j.field.contenttype.parser;

import [I;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Vector;

public class ContentTypeParser
  implements ContentTypeParserConstants
{
  private static int[] jj_la1_0;
  private Vector jj_expentries;
  private int[] jj_expentry;
  private int jj_gen;
  SimpleCharStream jj_input_stream;
  private int jj_kind;
  private final int[] jj_la1;
  public Token jj_nt;
  private int jj_ntk;
  private ArrayList paramNames;
  private ArrayList paramValues;
  private String subtype;
  public Token token;
  public ContentTypeParserTokenManager token_source;
  private String type;

  static
  {
    jj_la1_0();
  }

  public ContentTypeParser(InputStream paramInputStream)
  {
    this(paramInputStream, null);
  }

  public ContentTypeParser(InputStream paramInputStream, String paramString)
  {
    this.paramNames = new ArrayList();
    this.paramValues = new ArrayList();
    this.jj_la1 = new int[3];
    this.jj_expentries = new Vector();
    this.jj_kind = -1;
    try
    {
      this.jj_input_stream = new SimpleCharStream(paramInputStream, paramString, 1, 1);
      this.token_source = new ContentTypeParserTokenManager(this.jj_input_stream);
      this.token = new Token();
      this.jj_ntk = -1;
      this.jj_gen = 0;
      int i = 0;
      if (i < 3)
      {
        this.jj_la1[i] = -1;
        ++i;
      }
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new RuntimeException(localUnsupportedEncodingException);
    }
  }

  public ContentTypeParser(Reader paramReader)
  {
    this.paramNames = new ArrayList();
    this.paramValues = new ArrayList();
    this.jj_la1 = new int[3];
    this.jj_expentries = new Vector();
    this.jj_kind = -1;
    this.jj_input_stream = new SimpleCharStream(paramReader, 1, 1);
    this.token_source = new ContentTypeParserTokenManager(this.jj_input_stream);
    this.token = new Token();
    this.jj_ntk = -1;
    this.jj_gen = 0;
    for (int i = 0; i < 3; ++i)
      this.jj_la1[i] = -1;
  }

  public ContentTypeParser(ContentTypeParserTokenManager paramContentTypeParserTokenManager)
  {
    this.paramNames = new ArrayList();
    this.paramValues = new ArrayList();
    this.jj_la1 = new int[3];
    this.jj_expentries = new Vector();
    this.jj_kind = -1;
    this.token_source = paramContentTypeParserTokenManager;
    this.token = new Token();
    this.jj_ntk = -1;
    this.jj_gen = 0;
    for (int i = 0; i < 3; ++i)
      this.jj_la1[i] = -1;
  }

  private final Token jj_consume_token(int paramInt)
    throws ParseException
  {
    Token localToken1 = this.token;
    if (localToken1.next != null)
      this.token = this.token.next;
    while (true)
    {
      this.jj_ntk = -1;
      if (this.token.kind != paramInt)
        break;
      this.jj_gen = (1 + this.jj_gen);
      return this.token;
      Token localToken2 = this.token;
      Token localToken3 = this.token_source.getNextToken();
      localToken2.next = localToken3;
      this.token = localToken3;
    }
    this.token = localToken1;
    this.jj_kind = paramInt;
    throw generateParseException();
  }

  private static void jj_la1_0()
  {
    int[] arrayOfInt = new int[3];
    arrayOfInt[0] = 2;
    arrayOfInt[1] = 16;
    arrayOfInt[2] = 3670016;
    jj_la1_0 = arrayOfInt;
  }

  private final int jj_ntk()
  {
    int i;
    Token localToken1 = this.token.next;
    this.jj_nt = localToken1;
    if (localToken1 == null)
    {
      Token localToken2 = this.token;
      Token localToken3 = this.token_source.getNextToken();
      localToken2.next = localToken3;
      i = localToken3.kind;
      this.jj_ntk = i;
    }
    while (true)
    {
      return i;
      i = this.jj_nt.kind;
      this.jj_ntk = i;
    }
  }

  public static void main(String[] paramArrayOfString)
    throws ParseException
  {
    try
    {
      new ContentTypeParser(System.in).parseLine();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void ReInit(InputStream paramInputStream)
  {
    ReInit(paramInputStream, null);
  }

  public void ReInit(InputStream paramInputStream, String paramString)
  {
    try
    {
      this.jj_input_stream.ReInit(paramInputStream, paramString, 1, 1);
      this.token_source.ReInit(this.jj_input_stream);
      this.token = new Token();
      this.jj_ntk = -1;
      this.jj_gen = 0;
      int i = 0;
      if (i < 3)
      {
        this.jj_la1[i] = -1;
        ++i;
      }
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new RuntimeException(localUnsupportedEncodingException);
    }
  }

  public void ReInit(Reader paramReader)
  {
    this.jj_input_stream.ReInit(paramReader, 1, 1);
    this.token_source.ReInit(this.jj_input_stream);
    this.token = new Token();
    this.jj_ntk = -1;
    this.jj_gen = 0;
    for (int i = 0; i < 3; ++i)
      this.jj_la1[i] = -1;
  }

  public void ReInit(ContentTypeParserTokenManager paramContentTypeParserTokenManager)
  {
    this.token_source = paramContentTypeParserTokenManager;
    this.token = new Token();
    this.jj_ntk = -1;
    this.jj_gen = 0;
    for (int i = 0; i < 3; ++i)
      this.jj_la1[i] = -1;
  }

  public final void disable_tracing()
  {
  }

  public final void enable_tracing()
  {
  }

  public ParseException generateParseException()
  {
    this.jj_expentries.removeAllElements();
    boolean[] arrayOfBoolean = new boolean[24];
    for (int i = 0; i < 24; ++i)
      arrayOfBoolean[i] = false;
    if (this.jj_kind >= 0)
    {
      arrayOfBoolean[this.jj_kind] = true;
      this.jj_kind = -1;
    }
    for (int j = 0; j < 3; ++j)
      if (this.jj_la1[j] == this.jj_gen)
        for (int i1 = 0; i1 < 32; ++i1)
          if ((jj_la1_0[j] & 1 << i1) != 0)
            arrayOfBoolean[i1] = true;
    for (int k = 0; k < 24; ++k)
      if (arrayOfBoolean[k] != 0)
      {
        this.jj_expentry = new int[1];
        this.jj_expentry[0] = k;
        this.jj_expentries.addElement(this.jj_expentry);
      }
    [I[] arrayOf[I = new int[this.jj_expentries.size()][];
    for (int l = 0; l < this.jj_expentries.size(); ++l)
      arrayOf[I[l] = ((int[])(int[])this.jj_expentries.elementAt(l));
    return new ParseException(this.token, arrayOf[I, tokenImage);
  }

  public final Token getNextToken()
  {
    if (this.token.next != null)
      this.token = this.token.next;
    while (true)
    {
      this.jj_ntk = -1;
      this.jj_gen = (1 + this.jj_gen);
      return this.token;
      Token localToken1 = this.token;
      Token localToken2 = this.token_source.getNextToken();
      localToken1.next = localToken2;
      this.token = localToken2;
    }
  }

  public ArrayList getParamNames()
  {
    return this.paramNames;
  }

  public ArrayList getParamValues()
  {
    return this.paramValues;
  }

  public String getSubType()
  {
    return this.subtype;
  }

  public final Token getToken(int paramInt)
  {
    Token localToken1 = this.token;
    int i = 0;
    Object localObject = localToken1;
    if (i < paramInt)
    {
      Token localToken2;
      if (((Token)localObject).next != null)
        localToken2 = ((Token)localObject).next;
      while (true)
      {
        while (true)
        {
          ++i;
          localObject = localToken2;
        }
        localToken2 = this.token_source.getNextToken();
        ((Token)localObject).next = localToken2;
      }
    }
    return ((Token)localObject);
  }

  public String getType()
  {
    return this.type;
  }

  public final void parameter()
    throws ParseException
  {
    Token localToken = jj_consume_token(21);
    jj_consume_token(5);
    String str = value();
    this.paramNames.add(localToken.image);
    this.paramValues.add(str);
  }

  public final void parse()
    throws ParseException
  {
    Token localToken1 = jj_consume_token(21);
    jj_consume_token(3);
    Token localToken2 = jj_consume_token(21);
    this.type = localToken1.image;
    this.subtype = localToken2.image;
    while (true)
    {
      int i;
      if (this.jj_ntk == -1)
        i = jj_ntk();
      while (true)
        switch (i)
        {
        default:
          this.jj_la1[1] = this.jj_gen;
          return;
          i = this.jj_ntk;
        case 4:
        }
      jj_consume_token(4);
      parameter();
    }
  }

  public final void parseAll()
    throws ParseException
  {
    parse();
    jj_consume_token(0);
  }

  public final void parseLine()
    throws ParseException
  {
    int i;
    parse();
    if (this.jj_ntk == -1)
    {
      i = jj_ntk();
      switch (i)
      {
      default:
        this.jj_la1[0] = this.jj_gen;
      case 1:
      }
    }
    while (true)
    {
      while (true)
      {
        jj_consume_token(2);
        return;
        i = this.jj_ntk;
      }
      jj_consume_token(1);
    }
  }

  public final String value()
    throws ParseException
  {
    int i;
    if (this.jj_ntk == -1)
      i = jj_ntk();
    while (true)
      switch (i)
      {
      default:
        this.jj_la1[2] = this.jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
        i = this.jj_ntk;
      case 21:
      case 20:
      case 19:
      }
    Token localToken = jj_consume_token(21);
    while (true)
    {
      while (true)
      {
        return localToken.image;
        localToken = jj_consume_token(20);
      }
      localToken = jj_consume_token(19);
    }
  }
}